package com.levy.system;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import org.junit.Test;

import com.sun.management.UnixOperatingSystemMXBean;

public class SystemInformationByShell {

	@Test
	public void getRunTime() throws IOException {
		String[] cmd = {"/bin/sh","-c", "top -b -n 1"};
		Process process = Runtime.getRuntime().exec(cmd);
		BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); 		 
		String str;
		while((str=br.readLine())!=null){ 
			System.out.println("***"+str); 
		} 
		
		
		br = new BufferedReader(new InputStreamReader(process.getErrorStream())); 		
		while((str=br.readLine())!=null){ 
			System.out.println("***"+str); 
		} 
//		
//		br = new BufferedReader(new OutputStream(process.getOutputStream())); 		
//		while((str=br.readLine())!=null){ 
//			System.out.println("***"+str); 
//		} 
		
//		 Runtime.getRuntime().exec(new String[] {"/bin/sh","-c", "top -b 2>&1 | tee top.log"});
	}

}
